package com.ruoyi.lclook.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.lclook.domain.ProjectMessage;
import com.ruoyi.lclook.service.IProjectMessageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 案例留言Controller
 * 
 * @author Choi
 * @date 2021-08-17
 */
@RestController
@RequestMapping("/lclook/projectMessage")
public class ProjectMessageController extends BaseController
{
    @Autowired
    private IProjectMessageService projectMessageService;

    /**
     * 查询案例留言列表
     */
    @PreAuthorize("@ss.hasPermi('lclook:projectMessage:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProjectMessage projectMessage)
    {
        startPage();
        List<ProjectMessage> list = projectMessageService.selectProjectMessageList(projectMessage);
        return getDataTable(list);
    }

    /**
     * 导出案例留言列表
     */
    @PreAuthorize("@ss.hasPermi('lclook:projectMessage:export')")
    @Log(title = "案例留言", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ProjectMessage projectMessage)
    {
        List<ProjectMessage> list = projectMessageService.selectProjectMessageList(projectMessage);
        ExcelUtil<ProjectMessage> util = new ExcelUtil<ProjectMessage>(ProjectMessage.class);
        return util.exportExcel(list, "案例留言数据");
    }

    /**
     * 获取案例留言详细信息
     */
    @PreAuthorize("@ss.hasPermi('lclook:projectMessage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(projectMessageService.selectProjectMessageById(id));
    }

    /**
     * 新增案例留言
     */
    @PreAuthorize("@ss.hasPermi('lclook:projectMessage:add')")
    @Log(title = "案例留言", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectMessage projectMessage)
    {
        return toAjax(projectMessageService.insertProjectMessage(projectMessage));
    }

    /**
     * 修改案例留言
     */
    @PreAuthorize("@ss.hasPermi('lclook:projectMessage:edit')")
    @Log(title = "案例留言", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectMessage projectMessage)
    {
        return toAjax(projectMessageService.updateProjectMessage(projectMessage));
    }

    /**
     * 删除案例留言
     */
    @PreAuthorize("@ss.hasPermi('lclook:projectMessage:remove')")
    @Log(title = "案例留言", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(projectMessageService.deleteProjectMessageByIds(ids));
    }
}
